<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>过滤数据-每种类型获取一条</title>
    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script> -->
    <script src="lodash.min.js"></script>
    <script src="../helpers/bing.js"></script>
  </head>
  <body>
    <!-- <script>
      const allGroups = [
        {
          groupName: "TEN_RANGE_00001033_GROUPS",
          groupType: "ten",
          accuracy_array: [1, 0, 0],
          stats: {
            correctCount: 1,
            incorrectCount: 2,
            accuracyRate: 0.3333333333333333,
            maxConsecutiveCorrect: 1,
            maxConsecutiveIncorrect: 2,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 1,
            avgConsecutiveIncorrect: 2,
            currentConsecutiveCorrect: 0,
            currentConsecutiveIncorrect: 2,
          },
          forecast_type: "red_continuous_limit_2",
        },
        {
          groupName: "TWO_RANGE_00001034_GROUPS",
          groupType: "two",
          accuracy_array: [1, 1, 0],
          stats: {
            correctCount: 2,
            incorrectCount: 1,
            accuracyRate: 0.6666666666666666,
            maxConsecutiveCorrect: 2,
            maxConsecutiveIncorrect: 1,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 2,
            avgConsecutiveIncorrect: 1,
            currentConsecutiveCorrect: 2,
            currentConsecutiveIncorrect: 0,
          },
          forecast_type: "red_continuous_limit_3",
        },
        {
          groupName: "THREE_RANGE_00001035_GROUPS",
          groupType: "three",
          accuracy_array: [0, 1, 1],
          stats: {
            correctCount: 2,
            incorrectCount: 1,
            accuracyRate: 0.6666666666666666,
            maxConsecutiveCorrect: 1,
            maxConsecutiveIncorrect: 2,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 1,
            avgConsecutiveIncorrect: 2,
            currentConsecutiveCorrect: 1,
            currentConsecutiveIncorrect: 1,
          },
          forecast_type: "green_continuous_limit_3",
        },
        {
          groupName: "TEN_RANGE_00001036_GROUPS",
          groupType: "ten",
          accuracy_array: [0, 1, 1],
          stats: {
            correctCount: 1,
            incorrectCount: 2,
            accuracyRate: 0.3333333333333333,
            maxConsecutiveCorrect: 1,
            maxConsecutiveIncorrect: 2,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 1,
            avgConsecutiveIncorrect: 2,
            currentConsecutiveCorrect: 0,
            currentConsecutiveIncorrect: 2,
          },
          forecast_type: "red_continuous_limit_2",
        },
      ];

      const FOLDER_OPTIONS = [
        "two",
        "three",
        "four",
        "five",
        "six",
        "seven",
        "eight",
        "ten",
        "twelve",
        "sixteen",
        "twentyfour",
      ];

      // 过滤并去重，保留每个 groupType 的一条数据
      const filteredGroups = allGroups
        .filter((group) => FOLDER_OPTIONS.includes(group.groupType))
        .reduce((acc, group) => {
          // 如果还没有该类型的 groupType，则添加
          if (!acc.some((item) => item.groupType === group.groupType)) {
            acc.push(group);
          }
          return acc;
        }, []);

      console.log(filteredGroups);
    </script> -->

    <script>
      const allGroups = [
        {
          groupName: "TEN_RANGE_00001033_GROUPS",
          groupType: "ten",
          accuracy_array: [1, 0, 0],
          stats: {
            correctCount: 1,
            incorrectCount: 2,
            accuracyRate: 0.3333333333333333,
            maxConsecutiveCorrect: 1,
            maxConsecutiveIncorrect: 2,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 1,
            avgConsecutiveIncorrect: 2,
            currentConsecutiveCorrect: 0,
            currentConsecutiveIncorrect: 2,
          },
          forecast_type: "red_continuous_limit_2",
        },
        {
          groupName: "TWO_RANGE_00001034_GROUPS",
          groupType: "two",
          accuracy_array: [1, 1, 0],
          stats: {
            correctCount: 2,
            incorrectCount: 1,
            accuracyRate: 0.6666666666666666,
            maxConsecutiveCorrect: 2,
            maxConsecutiveIncorrect: 1,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 2,
            avgConsecutiveIncorrect: 1,
            currentConsecutiveCorrect: 2,
            currentConsecutiveIncorrect: 0,
          },
          forecast_type: "red_continuous_limit_3",
        },
        {
          groupName: "THREE_RANGE_00001035_GROUPS",
          groupType: "three",
          accuracy_array: [0, 1, 1],
          stats: {
            correctCount: 2,
            incorrectCount: 1,
            accuracyRate: 0.6666666666666666,
            maxConsecutiveCorrect: 1,
            maxConsecutiveIncorrect: 2,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 1,
            avgConsecutiveIncorrect: 2,
            currentConsecutiveCorrect: 1,
            currentConsecutiveIncorrect: 1,
          },
          forecast_type: "green_continuous_limit_3",
        },
        {
          groupName: "TEN_RANGE_00001036_GROUPS",
          groupType: "ten",
          accuracy_array: [0, 1, 1],
          stats: {
            correctCount: 1,
            incorrectCount: 2,
            accuracyRate: 0.3333333333333333,
            maxConsecutiveCorrect: 1,
            maxConsecutiveIncorrect: 2,
            consecutiveCorrectSegments: 1,
            consecutiveIncorrectSegments: 1,
            avgConsecutiveCorrect: 1,
            avgConsecutiveIncorrect: 2,
            currentConsecutiveCorrect: 0,
            currentConsecutiveIncorrect: 2,
          },
          forecast_type: "red_continuous_limit_2",
        },
      ];

      const FOLDER_OPTIONS = [
        "two",
        "three",
        "four",
        "five",
        "six",
        "seven",
        "eight",
        "ten",
        "twelve",
        "sixteen",
        "twentyfour",
      ];

      // 使用 lodash 的链式编程进行简化
      const filteredGroups = _(allGroups)
        .filter((group) => FOLDER_OPTIONS.includes(group.groupType)) // 先过滤出有效的 groupType
        .uniqBy("groupType") // 去重，保留每个 groupType 的第一条数据
        .value(); // 获取最终的结果

      console.log(filteredGroups);
    </script>
  </body>
</html>
